package  de.tum.softwarengineering1.ws201112.team11.sudoku.model;

public class Cell {
    private int line;
    private int column;
    private int value;

    private boolean isFixed;

    private int boardSize = 9;

    public Cell(int line, int column) {
	this(line, column, 0);
    }

    Cell(int line, int column, int value) {
	this(line, column, value, false);
    }

    Cell(int line, int column, int value, boolean fixed) {
	this.setLine(line);
	this.setColumn(column);
	this.setValue(value);
	this.setFixed(fixed);
    }

    public void setOverallSize(int size) {
	boardSize = size;
    }

    int box() {
	assert Math.sqrt(boardSize) * Math.sqrt(boardSize) == boardSize;
	int box = 0;
	int boxSize = Double.valueOf(Math.sqrt(boardSize)).intValue();
	box += 3 * (getLine() / boxSize);
	box += getColumn() / boxSize;
	return box;
    }

    public boolean isFixed() {
	return isFixed;
    }

    public void setFixed(boolean isFixed) {
	this.isFixed = isFixed;
    }

    /*
     * Two cells are called equal if they have the same coordinates!
     * 
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(Object obj) {
	if (obj == null)
	    return false;
	if (!(obj instanceof Cell))
	    return false;

	Cell rhs = (Cell) obj;
	return (this.getLine() == rhs.getLine() && this.getColumn() == rhs.getColumn());
    }

    @Override
    public int hashCode() {
	int hash = 1;
	hash = hash * 31 + Integer.valueOf(getLine()).hashCode();
	hash = hash * 31 + Integer.valueOf(getColumn()).hashCode();
	return hash;
    }

	public int getLine() {
		return line;
	}

	public void setLine(int line) {
		this.line = line;
	}

	public int getColumn() {
		return column;
	}

	public void setColumn(int column) {
		this.column = column;
	}

	public int getValue() {
		return value;
	}

	public void setValue(int value) {
		this.value = value;
	}
}
